﻿package string;

/**
 * 统计字符串出现的次数（相邻的字符串）
 * @author Administrator
 *
 */
public class 字符串的统计字符串 {

	public static String caculate(String str){
		if(str==null||str.equals("")){
			return str;
		}
		char[] chas =str.toCharArray();
		int num=1;
		String res = String.valueOf(chas[0]);
		for(int i=1; i<chas.length;i++){
			if(chas[i]==chas[i-1]){
				num++;
			}else{
				res = res +"_" +num+"_"+chas[i];
				num =0;
			}
		}
		res = res + "_" +num;
		return res;
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		System.out.println(caculate("aaaabbbbsssdddffwewwww"));
	}

}
